Cannot convert parameter 1 from 'short *' to 'int *' [closed]

Posted by Torben Carrington on Game Development See other posts from Game Development or by Torben Carrington
Published on 2012-06-21T01:19:45Z Indexed on 2012/06/21 3:26 UTC
Read the original article Hit count: 421

Filed under:

I'm trying to learn pointers and since I recently learned that short int takes up less memory [2 bytes as apposed to the long int's memory usage of 4 which is the default for int] I wanted to create a pointer that uses the memory address of a short integer.

I'm following a tutorial in my book about Pointers and it's using the Swap function. The problem is I receive this error the moment I change everything from int to short int:

error C2664: 'Swap' : cannot convert parameter 1 from 'short *' to 'int *' 1> Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast

Since my code is so small here is the whole thing:

void Swap(short int *sipX, short int *sipY)

{

short int siTemp = *sipX;

*sipX = *sipY;

*sipY = siTemp;
}



int main()

{

short int siBig = 100;
short int siSmall = 1;

std::cout << "Pre-Swap: " << siBig << " " << siSmall << std::endl;
Swap(&siBig, &siSmall);
std::cout << "Post-Swap: " << siBig << " " << siSmall << std::endl;

return 0;
}

© Game Development or respective owner

Related posts about c++